if (!jsx3.lang.Class.forName("ux.cdb.admin.approvePkg.ProvRcpPkg")) {

/**
 * Define the <code>name of class</code> class.
 * This class inherit from <code>jsx3.gui.Block<code> GUI class.
 */
jsx3.Class.defineClass(
		"ux.cdb.admin.approvePkg.ProvRcpPkg",
		jsx3.gui.Block,
		null,
		function (objRoot) {
			/**
			* tool functions:
			*/
			objRoot.prototype.property = function(name, token) {
				return ux.megatron.Main.getServer().getDynamicProperty(name, token);
			};

			/**
			 * This method will be called after UI file has deserialized.
			 */
			objRoot.prototype.onAfterDeserialize = function() {
				this.blkDesc = this.get("blkDesc");
				this.mtxProvRcpPkg = this.get("mtxProvRcpPkg");
				this.blkDesc.setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
				this.curPage = ux.megatron.Main.getServer().getDynamicProperty("@cdb@apvPkg@curPage");
				this.pageSize = ux.megatron.Main.getServer().getDynamicProperty("@cdb@apvPkg@pageNum");
				this.pagebar = this.get("blkPageWheel");
                this.pagebar.initialize();
				this.pagebar.bindWithMatrix(this, this.loadPagination, this.mtxProvRcpPkg);
			}
			
			objRoot.prototype.loadPagination = function(msg) {
                this.curPage = (msg && msg.currentPageNumber) ? msg.currentPageNumber : (this.curPage || 1);
                this.loadProvRcpPkgData();
            };
			
			objRoot.prototype.loadUIojbloadPagination = function(msg) {
                this.loadUIojb.curPage = (msg && msg.currentPageNumber) ? msg.currentPageNumber : (this.loadUIojb.curPage || 1);
                this.loadRcpPkgData(this.loadUIojb.parentId);
            };
			

			/**
			* initialize Province receipt package UI
			*/
			objRoot.prototype.initUI = function(parentId){
				if(parentId){
					this.parentId = parentId;
					this.blkDesc.show();
					if(this.blkRcpPkgList){
						this.blkRcpPkgList.hide();
					}
					this.loadProvRcpPkgData();
				}
			}

			/**
			* invoke when user choose a province receipt package
			* params target{record} choosed cdf record
			*/
			objRoot.prototype.onChooseProvRcpPkg = function(target){
				var me = this;
				if(!this.get("blkRcpPkgList")){
					this.loadDetailPane();
				}else{
					this.get("btnDetail").setEnabled(jsx3.gui.Form.STATEDISABLED, true);;
					this.blkDesc.hide();
					this.blkRcpPkgList.show();
					this.loadUIojb.parentId = target.getSelectedNodes().get(0).getAttribute("jsxid");
					this.loadRcpPkgData(this.loadUIojb.parentId);
				}
			}

			/**
			* invoke when user choose a receipt package
			*/
			objRoot.prototype.onLoadContractDetailDlg = function(){
				var parent = ux.megatron.Main.getServer().getBodyBlock();
				var me = this;
				ux.megatron.Main.loadUIResourceAsync(parent,
						"ux.cdb.admin", 
						"ux/cdb/admin/approvePkg/ui/contractDetailDlg.xml",
						me,me.onLoadcontractDetialDlgSuccess);
			}

			objRoot.prototype.onLoadcontractDetialDlgSuccess = function(objEvent){
				this.detailDlg = objEvent.obj;
				objEvent.obj.opener = this;
				var selectedid = this.mtxRcpPkg.getSelectedNodes().get(0).getAttribute("jsxid");
				this.detailDlg.get("blkWorld").onInitializeUI(selectedid);
			}

			/**
			* load detail pane of province receipt package
			*/
			objRoot.prototype.loadDetailPane = function(){
				var parent = this.get("paneProvPkgDetail");
				var me = this;
				this.blkDesc.hide();

				ux.megatron.Main.loadUIResourceAsync(parent,
						"ux.cdb.admin", 
						"ux/cdb/admin/approvePkg/ui/rcpPkgListByProv.xml",
						me,me.onLoadRcpPkgListSuccess);
			}

			objRoot.prototype.onLoadRcpPkgListSuccess = function(objEvent){
				this.blkRcpPkgList = this.get("blkRcpPkgList");
				this.blkRcpPkgList.show();
				this.get("btnDetail").disable();
				this.mtxRcpPkg = this.get("mtxRcpPkg");

				this.loadUIojb = objEvent.obj;
				this.loadUIojb.curPage = ux.megatron.Main.getServer().getDynamicProperty("@cdb@apvPkg@curPage");
				this.loadUIojb.pageSize = ux.megatron.Main.getServer().getDynamicProperty("@cdb@apvPkg@pageNum");
				this.loadUIojb.pagebar = this.loadUIojb.get("blkPageWheel");
                this.loadUIojb.pagebar.initialize();
				this.loadUIojb.pagebar.bindWithMatrix(this, this.loadUIojbloadPagination, this.mtxRcpPkg);
				
				this.loadUIojb.parentId = this.mtxProvRcpPkg.getSelectedNodes().get(0).getAttribute("jsxid");
				this.loadRcpPkgData(this.loadUIojb.parentId);
			}

			/**
			* load Province Receipt Package Data
			*/
			objRoot.prototype.loadProvRcpPkgData = function(){
				var me = this;
				this.curPage = ux.megatron.Main.getServer().getDynamicProperty("@cdb@apvPkg@curPage");
				this.pageSize = ux.megatron.Main.getServer().getDynamicProperty("@cdb@apvPkg@pageNum");
				ux.megatron.util.Dwr.callDwr("RetailStudentLoanBatchAuditingUCC",
						"getBatchApprovalInfoListByConcentrateApprovalInfoId",[this.parentId,this.curPage,this.pageSize],
						me,me.callBackProvRcpPkgData,
						"RetailStudentLoanBatchAuditingUCC");
			}
			objRoot.prototype.callBackProvRcpPkgData = function(dwrObjectList){
				if(!dwrObjectList){
					jsx3.log("DWR loadProvRcpPkgData failed");
					return;
				}
				this.totalRecordCount = dwrObjectList.content.page.count;
				this.totalPages = (this.totalRecordCount % this.pageSize > 0) ? (parseInt(this.totalRecordCount / this.pageSize) + 1) : (this.totalRecordCount / this.pageSize);
				if (this.totalPages == 0) this.totalPages = 1;
				this.pagebar.setValue(this.curPage,this.totalPages,this.pageSize,this.totalRecordCount); 

				var cdfDoc = ux.megatron.util.Dwr.toCdfDocument(dwrObjectList.content.data,"jsxroot",{"batchApprovalInfoId":"jsxid"});
				this.mtxProvRcpPkg.setSourceXML(cdfDoc);
				this.mtxProvRcpPkg.repaintData();
			}
			
			/**
			* load receipt package data
			*/
			objRoot.prototype.loadRcpPkgData = function(parentId){
				var me = this;
				ux.megatron.util.Dwr.callDwr("RetailStudentLoanBatchExamUCC",
						"getCountryBatchInfoListFromProvince",[this.loadUIojb.parentId,this.curPage,this.pageSize],
						me,me.callBackgetCountryBatchInfoListFromProvince,
						"RetailStudentLoanBatchExamUCC");
			}
			objRoot.prototype.callBackgetCountryBatchInfoListFromProvince = function(dwrObjectList){
				if(!dwrObjectList){
					jsx3.log("DWR loadRcpPkgData failed");
					return;
				}
				this.loadUIojb.totalRecordCount = dwrObjectList.content.page.count;
				this.loadUIojb.totalPages = (this.loadUIojb.totalRecordCount % this.loadUIojb.pageSize > 0) ? (parseInt(this.loadUIojb.totalRecordCount / this.loadUIojb.pageSize) + 1) : (this.loadUIojb.totalRecordCount / this.loadUIojb.pageSize);
				if (this.loadUIojb.totalPages == 0) this.loadUIojb.totalPages = 1;
				this.loadUIojb.pagebar.setValue(this.loadUIojb.curPage,this.loadUIojb.totalPages,this.loadUIojb.pageSize,this.loadUIojb.totalRecordCount); 

				var cdfDoc = ux.megatron.util.Dwr.toCdfDocument(dwrObjectList.content.data,"jsxroot",{"batchApprovalInfoId":"jsxid"});
				this.mtxRcpPkg.setSourceXML(cdfDoc);
				this.mtxRcpPkg.repaintData();
			}
		});
}

